﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_301_02
    {

        //图F.4  ISYC 301-02-粗柄带颈螺纹切削丝锥
        public static void Coarseshankcuttingtap1_j(Dictionary<string, Object> data)  //  粗柄带颈螺纹切削丝锥
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层         
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线           
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线           
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            // double sl_ = Convert.ToDouble(data["oal"]);
            // double scale = Convert.ToDouble(data["scale"]);
            /* double sl_ = 45;
             double scale = 1;
             double tcl = 10;
             double td = 30;
             double tcpd = 28;
             double thl = 95;
             double dn = 24;
             double ls = 100;
             double oal = 242.5;
             double dconms = 40;
             double drvl = 33.33;
             double lu = 138;
             double lpr = 154;
            double tg = 10;
            double fha = 15;
             */
            double scale = Convert.ToDouble(data["scale"]);
            double tcl = Convert.ToDouble(data["tcl"]);
            double td = Convert.ToDouble(data["td"]);
            double tcpd = Convert.ToDouble(data["tcpd"]);
            double thl = Convert.ToDouble(data["thl"]);
            double dn = Convert.ToDouble(data["dn"]);
            double ls = Convert.ToDouble(data["ls"]);
            double oal = Convert.ToDouble(data["oal"]);
            double dconms = Convert.ToDouble(data["dconms"]);
            double drvl = Convert.ToDouble(data["drvl"]);
            double lu = Convert.ToDouble(data["lu"]);
            double lpr = Convert.ToDouble(data["lpr"]);
            double fha = Convert.ToDouble(data["fha"]);
            double tg = Convert.ToDouble(data["tg"]);
            double tg_ = tg * pi / 180;
            double fha_ = fha * pi / 180;
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal);
            Vector2 p1 = fun.Polar(p0, pi / 2, tcpd / 2.0);
            Vector2 p2 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p3 = fun.Polar(p1, tg_ / 2, (thl / 8.0) / Math.Cos(tg_ / 2));
            Vector2 p4 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p5 = fun.Polar(p1, pi / -2, tcpd / 6.0);
            Vector2 p6 = fun.Polar(p3, pi / -2, fun.CalDistance(p3, p4) / 10.0);
            Vector2 p7 = fun.Polar(p2, pi / 2, tcpd / 3.0);
            Vector2 p7_0 = fun.Polar(p7, tg_ / 2, thl);
            Vector2 p8 = fun.Inters(p7, p7_0, p3, p4);
            Vector2 p9 = fun.Polar(p0, 0, thl);
            Vector2 p10 = fun.Polar(p9, pi / 2, p3.Y);
            Vector2 p11 = fun.mirrorpoint(p10, p0_1, p0_2);
            double q = (p3.Y - p6.Y) / 2.0;//刀齿高度
            Vector2 p12 = fun.Polar(p10, pi / 2, q);
            Vector2 p12_1 = fun.Polar(p8, pi / 2, 0.1);
            Vector2 p12_2 = fun.Polar(p12_1, fha_, thl);
            Vector2 p13 = fun.Polar(p10, pi / -2, fun.CalDistance(p8, p4));
            Vector2 p15 = fun.Polar(p4, pi / -2, q);
            Vector2 p16 = fun.Polar(p13, pi / -2, q);
            Vector2 p14 = fun.Polar(p8, pi / 2, q);
            Vector2 p14_1 = fun.Polar(p14, pi / 2, 0.1);
            Vector2 p14_2 = fun.Polar(p14_1, fha_, thl);
            Vector2 p4_1 = fun.Polar(p4, pi / -2, 0.1 * scale);
            Vector2 p4_2 = fun.Polar(p4_1, fha_, thl);
            Vector2 p15_1 = fun.Polar(p15, pi / -2, 0.1 * scale);
            Vector2 p15_2 = fun.Polar(p15_1, fha_, thl);
            Line line1 = new Line(p14_1, p14_2);
            Arc arc1 = fun.DrawArc5(p12, line1, p14);
            Arc arc2 = fun.DrawArc4(p10, arc1.Radius, p8, 0);
            Arc arc3 = fun.DrawArc4(p4, arc2.Radius, p13, 0);
            Arc arc4 = fun.DrawArc4(p15, arc1.Radius, p16, 0);
            var polyline1 = Pus.AddPointsToLwPolyLine(p5, p6, p3, p1, p2, p4, p8, p7);
            Vector2 p17_0 = fun.Polar(p10, pi / 2 + pi / 4, thl);
            Vector2 p17 = fun.Inters1(p10, p17_0, arc1, 0);
            Vector2 p18_0 = fun.Polar(p17, fun.CalAngle(p17, p10) - pi / 2, thl);
            Vector2 p18 = fun.Inters1(p17, p18_0, arc2, 1);
            Vector2 p19_0 = fun.Polar(p16, 165 * pi / 180, thl);
            Vector2 p19 = fun.Inters1(p16, p19_0, arc3, 1);
            Vector2 p20_0 = fun.Polar(p19, fun.CalAngle(p19, p16) - pi / 2, thl);
            Vector2 p20 = fun.Inters1(p19, p20_0, arc4, 0);
            Vector2 p21_1 = fun.Polar(p12, pi, thl / 4.0);
            Vector2 p21_2 = fun.Polar(p12_1, pi / -2, thl);
            Vector2 p21 = fun.Inters1(p21_1, p21_2, arc1, 1);
            Vector2 p21_3 = fun.Polar(p0, pi / 2, td / 2.0);
            Vector2 p21_4 = fun.Polar(p21_3, 0, thl);
            Line line5 = new Line(p21_3, p21_4);
            Arc arc5 = fun.DrawArc5(p21, line5, p3);
            Vector2 p22 = fun.Polar(p3, fun.CalAngle(p3, p6), fun.CalDistance(p3, p6) / 2.0);
            Vector2 p23_0 = fun.Polar(p22, fun.CalAngle(p3, p21) + 1 * pi / 180, oal);
            Vector2 p23 = fun.Inters1(p23_0, p22, arc1, 0);
            Arc arc6 = fun.DrawArc4(p23, arc5.Radius, p22, 0);
            Vector2 p24_0 = fun.Polar(p6, fun.CalAngle(p5, p6), thl);
            Vector2 p25_0 = fun.Polar(p3, fun.CalAngle(p1, p3), thl);
            var polyline2 = Pus.AddPointsToLwPolyLine(p18, p17, p10, p16, p19, p17, p19, p20);
            var a2c = Pus.ToV2(arc2.Center);//arc2的圆心
            var a3c = Pus.ToV2(arc3.Center);//arc3的圆心
            var z1 = fun.CalAngle(a2c, p18) - fun.CalAngle(a2c, p10);//一个齿的向量            
            double xl1 = fun.CalAngle(a2c, p8) - fun.CalAngle(a2c, p10);//arc2的向量
            double zc1 = (arc2.Radius * 2) * pi;//arc2的满园时的周长
            double zc1_1 = (xl1 / (2 * pi)) * zc1;//arc2弧线的周长
            double zc1_2 = (z1 / (2 * pi)) * zc1;
            int cs1 = (int)(zc1_1 / zc1_2);//arc2弧线上有多少个齿
            double i = 0;
            Vector2 c1 = p18;
            Vector2 c2 = p20;
            Vector2 c4;
            do
            {
                Vector2 c3 = fun.PointRotate(a2c, p17, 2 * pi - z1 * i);
                c4 = fun.PointRotate(a2c, p18, 2 * pi - z1 * i);
                Vector2 c5 = fun.PointRotate(a3c, p19, 2 * pi + z1 * i);
                Vector2 c6 = fun.PointRotate(a3c, p20, 2 * pi + z1 * i);
                var polyline3 = Pus.AddPointsToLwPolyLine(c4, c3, c1, c2, c5, c3, c5, c6);
                if (i < cs1)
                {
                    polyline3 = Pus.AddPointsToLwPolyLine(c4, c3, c1, c2, c5, c3, c5, c6);
                    fun.PolyFill(dxf, polyline3, 0.5, contour);
                    if (i == cs1 - 1)
                    {
                        polyline3 = Pus.AddPointsToLwPolyLine(c4, c6, p4, p8, c4);
                        fun.PolyFill(dxf, polyline3, 0.5, contour);
                    }
                }
                i++;
                c1 = c4;
                c2 = c6;
            } while (i < cs1);
            var a5c = Pus.ToV2(arc5.Center);
            var a6c = Pus.ToV2(arc6.Center);
            var a5x = fun.CalAngle(a5c, p3) - fun.CalAngle(a5c, p21);//arc5的向量
            var a5zh = arc5.Radius * 2 * pi;
            var a5d = a5x / (pi * 2) * a5zh;//arc5弧线周长
            Vector2 c4_0 = fun.Polar(c4, pi / 2, thl);
            Vector2 p24 = fun.Inters(c4, c4_0, p6, p24_0);
            Vector2 p25 = fun.Inters(c4, c4_0, p3, p25_0);
            Vector2 p26_0 = fun.Polar(p25, pi / -4, thl);
            Vector2 p26 = fun.Inters1(p25, p26_0, arc6, 0);
            Vector2 p27_0 = fun.Polar(p26, pi / 4, thl);
            Vector2 p27 = fun.Inters1(p26, p27_0, arc5, 1);
            Vector2 p28 = fun.Polar(p26, pi / -2, fun.CalDistance(p25, p24));
            Vector2 p29 = fun.Polar(p27, pi / -2, fun.CalDistance(p25, p24));
            var z2 = fun.CalAngle(a5c, p25) - fun.CalAngle(a5c, p27);//一个齿的向量
            var z2d = z2 / (2 * pi) * a5zh;//齿2在arc5中的周长
            int cs2 = (int)(a5d / z2d);
            double n = 0;
            double m = fun.CalDistance(p25, p24);
            Vector2 d1 = p25;
            Vector2 d4 = p24;
            for (; n < cs2; n++)
            {
                Vector2 d2 = fun.PointRotate(a5c, p26, z2 * n);
                Vector2 d3 = fun.PointRotate(a5c, p27, z2 * n);
                Vector2 d6 = fun.Polar(d3, pi / -2, m);
                if (m > 1)
                {
                    d4 = fun.Polar(d1, pi / -2, m);
                    Vector2 d5 = fun.Polar(d2, pi / -2, m);
                    d6 = fun.Polar(d3, pi / -2, m);
                    var polyline5 = Pus.AddPointsToLwPolyLine(d1, d2, d3, d6, d5, d2, d5, d4);
                    fun.PolyFill(dxf, polyline5, 0.5, contour);
                }
                else
                {
                    if (n == cs2 - 1)
                    {
                        Vector2 di_0 = fun.Polar(d1, pi / -4, thl);
                        Vector2 di = fun.Inters1(d1, di_0, arc1, 0);
                        Line lineq1 = new Line(d1, di);
                        fun.drawBline(dxf, lineq1, 0.5, contour);
                    }
                    else
                    {
                        m = 0;
                        d4 = fun.Polar(d1, pi / -2, m);
                        Vector2 d5 = fun.Polar(d2, pi / -2, m);
                        d6 = fun.Polar(d3, pi / -2, m);
                        var polyline5 = Pus.AddPointsToLwPolyLine(d1, d2, d3, d6, d5, d2, d5, d4);
                        fun.PolyFill(dxf, polyline5, 0.5, contour);
                    }
                }
                d1 = d3;
                d4 = d6;
                m -= 0.5 / scale;
            }
            Vector2 p30 = fun.Polar(p11, pi / 2, fun.CalDistance(p3, p6) * (3 / 2.0));
            Vector2 p31_1 = fun.Polar(fun.Polar(p15, pi / -2, td / 2.0), 0, (p11.X - p15.X) * (3 / 22.0));
            //Vector2 p31_2 = fun.Polar(p31_1, pi / 2, thl);
            Vector2 p31_2 = new Vector2(p31_1.X, p31_1.Y + thl);
            Vector2 p31 = fun.Inters1(p31_1, p31_2, arc4, 0);
            Vector2 p11_1 = fun.Polar(p0, pi / -2, td / 2.0);
            Vector2 p11_2 = fun.Polar(p11_1, 0, thl);
            Line line6 = new Line(p11_1, p11_2);
            Arc arc7 = fun.DrawArc5(p31, line6, p11);
            Arc arc8 = fun.DrawArc4(p31, arc7.Radius, p30, 0);
            Vector2 a7c = Pus.ToV2(arc7.Center);
            Vector2 p32 = fun.Polar(p11, fun.CalAngle(a7c, p11), fun.CalDistance(p25, p26));
            Vector2 p33 = fun.Polar(p31, fun.CalAngle(a7c, p31), fun.CalDistance(p25, p26));
            Arc arc9 = fun.DrawArc4(p33, arc7.Radius + fun.CalDistance(p25, p26), p32, 0);
            Vector2 p34_0 = fun.Polar(p11, -126 * pi / 180, thl);
            Vector2 p34 = fun.Inters1(p34_0, p11, arc9, 0);
            Vector2 p35_0 = fun.Polar(p34, fun.CalAngle(p34, p11) + pi / 2, thl);
            Vector2 p35 = fun.Inters1(p34, p35_0, arc7, 1);
            Vector2 p36 = fun.Polar(p34, pi / 2, fun.CalDistance(p30, p11));
            Vector2 p37 = fun.Polar(p35, pi / 2, fun.CalDistance(p30, p11));
            double z3 = fun.CalAngle(a7c, p35) - fun.CalAngle(a7c, p11);//一个齿的向量
            var a7x = fun.CalAngle(a7c, p31) - fun.CalAngle(a7c, p11);//arc7的向量
            var a7zh = arc7.Radius * 2 * pi;
            var a7d = a7x / (pi * 2) * a7zh;//arc7弧线周长
            var z3d = z3 / (2 * pi) * a7zh;//齿2在arc7中的周长
            int cs3 = (int)(a7d / z3d);//齿2在arc7的数量
            i = 0;
            n = fun.CalDistance(p30, p11);
            c1 = p11;
            c4 = p30;
            for (; i < cs3 + 1; i++)
            {
                if (n > 1)
                {
                    n = n;
                }
                else
                {
                    n = 0;
                }
                c2 = fun.PointRotate(a7c, p34, -z3 * i);
                var c3 = fun.PointRotate(a7c, p35, -z3 * i);
                var c5 = fun.Polar(c2, pi / 2, n);
                var c6 = fun.Polar(c3, pi / 2, n);
                var polyline6 = Pus.AddPointsToLwPolyLine(c6, c5, c4, c1, c2, c5, c2, c3);
                if (i == cs3)
                {
                    var c3_0 = fun.Polar(c3, fun.CalAngle(c2, c3), thl);
                    var c3_1 = fun.Inters1(c3, c3_0, arc3, 1);
                    polyline6 = Pus.AddPointsToLwPolyLine(c6, c5, c4, c1, c2, c5, c2, c3_1);
                }
                else
                {
                    polyline6 = Pus.AddPointsToLwPolyLine(c6, c5, c4, c1, c2, c5, c2, c3);
                }
                fun.PolyFill(dxf, polyline6, 0.5, contour);
                c4 = c6;
                c1 = c3;
                n -= 0.5 / scale;
            }
            Vector2 p38_0 = fun.Polar(p11, pi / 4 + 0.1 * pi / 180, thl);
            Vector2 p38_1 = fun.Polar(p0, pi / -2 - 0.1 * pi / 180, dn / 2.0);
            Vector2 p38_2 = fun.Polar(p38_1, 0, thl);
            Vector2 p38_3 = fun.Polar(p10, pi / -4, thl);
            Vector2 p38_4 = fun.Polar(p0, pi / 2, dn / 2.0);
            Vector2 p38_5 = fun.Polar(p38_4, 0, thl);
            Vector2 p38 = fun.Inters(p11, p38_0, p38_1, p38_2);
            Vector2 p39 = fun.Inters(p10, p38_3, p38_4, p38_5);
            Vector2 p40 = fun.Polar(p0, 0, oal);
            Vector2 p41 = fun.Polar(p40, pi / 2, dconms / 2.0);
            Vector2 p42 = fun.Polar(p41, pi, ls);
            Vector2 p43_0 = fun.Polar(p42, pi + pi / 4, thl);
            Vector2 p43 = fun.Inters(p42, p43_0, p38_4, p38_5);
            Vector2 p44 = fun.mirrorpoint(p41, p0_1, p0_2);
            Vector2 p45 = fun.mirrorpoint(p42, p0_1, p0_2);
            Vector2 p46 = fun.mirrorpoint(p43, p0_1, p0_2);
            Vector2 p47 = fun.Polar(p41, pi / -2, dconms / 20.0);
            Vector2 p48 = fun.Polar(p47, pi, drvl);
            Vector2 p49 = fun.Polar(p40, pi / 2, dconms / 15.0);
            Vector2 p50 = fun.Polar(p49, pi, fun.CalDistance(p47, p48));
            Vector2 p51 = fun.mirrorpoint(p47, p0_1, p0_2);
            Vector2 p52 = fun.mirrorpoint(p48, p0_1, p0_2);
            Vector2 p53 = fun.mirrorpoint(p49, p0_1, p0_2);
            Vector2 p54 = fun.mirrorpoint(p50, p0_1, p0_2);
            Arc arc10 = fun.DrawArc5(p30, new Line(p39, p38), p16);
            var polyline4 = Pus.AddPointsToLwPolyLine(p3, p6, p24, p25, p3);
            var polyline7 = Pus.AddPointsToLwPolyLine(p13, p10, p39, p38, p39, p43, p46, p38, p11, p30, p11, p38, p46, p45, p42, p43, p42, p41, p44, p45);
            var polyline8 = Pus.AddPointsToLwPolyLine(p49, p50, p48, p47, p51, p52, p54, p53);//尾巴部分
            var polyline9 = Pus.AddPointsToLwPolyLine(p47, p50, p48, p49, p53, p52, p54, p51);
            polyline9.Lineweight = Lineweight.W35;//Lineweight指线宽
            polyline9.Layer = additionalline;//Layer指图层
            /* dxf.AddEntity(new EntityObject[] { polyline1,polyline2,polyline4 ,polyline7,polyline8 ,polyline9 
             ,arc1,arc2,arc3,arc4,arc5 ,arc6 ,arc7,arc8 ,arc9 
              ,arc10 
             }) ;*/
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline7, 0.5, contour);
            fun.PolyFill(dxf, polyline8, 0.5, contour);
            fun.PolyFill(dxf, polyline9, 0.35, contour);
            fun.drawBArc(dxf, arc10, 0.5, contour);
            //局部图
            Vector2 p0_ = fun.Polar(p0, pi / -2, thl * 2);
            Vector2 p0_1_ = fun.Polar(p0_, pi, 5 * 2);
            Vector2 p0_2_ = fun.Polar(p0_, 0, thl * 2.5);
            Vector2 p1_ = fun.Polar(p0_, pi / 2, tcpd / 2.0 * 2);
            Vector2 p2_ = fun.mirrorpoint(p1_, p0_1_, p0_2_);
            Vector2 p3_ = fun.Polar(p1_, tg_ / 2, (thl / 8.0) / Math.Cos(tg_ / 2) * 2);
            Vector2 p4_ = fun.mirrorpoint(p3_, p0_1_, p0_2_);
            Vector2 p5_ = fun.Polar(p1_, pi / -2, tcpd / 6.0 * 2);
            Vector2 p6_ = fun.Polar(p3_, pi / -2, fun.CalDistance(p3_, p4_) / 10.0);
            Vector2 p7_ = fun.Polar(p2_, pi / 2, tcpd / 3.0 * 2);
            Vector2 p7_0_ = fun.Polar(p7_, tg_ / 2, thl * 2);
            Vector2 p8_ = fun.Inters(p7_, p7_0_, p3_, p4_);
            Vector2 p9_ = fun.Polar(p0_, 0, thl * 2);
            Vector2 p10_ = fun.Polar(p9_, pi / 2, p3.Y * 2);
            Vector2 p11_ = fun.mirrorpoint(p10_, p0_1_, p0_2_);
            double q_ = (p3.Y - p6.Y) / 2.0 * 2;//刀齿高度
            Vector2 p12_ = fun.Polar(p10_, pi / 2, q_);
            Vector2 p12_1_ = fun.Polar(p8_, pi / 2, 0.1 * 2);
            Vector2 p12_2_ = fun.Polar(p12_1_, fha_, thl * 2);
            Vector2 p13_ = fun.Polar(p10_, pi / -2, fun.CalDistance(p8_, p4_));
            Vector2 p15_ = fun.Polar(p4_, pi / -2, q_);
            Vector2 p16_ = fun.Polar(p13_, pi / -2, q_);
            Vector2 p14_ = fun.Polar(p8_, pi / 2, q_);
            Vector2 p14_1_ = fun.Polar(p14_, pi / 2, 0.1 * 2);
            Vector2 p14_2_ = fun.Polar(p14_1_, fha_, thl * 2);
            Vector2 p4_1_ = fun.Polar(p4_, pi / -2, 0.1 * scale * 2);
            Vector2 p4_2_ = fun.Polar(p4_1_, fha_, thl * 2);
            Vector2 p15_1_ = fun.Polar(p15_, pi / -2, 0.1 * scale * 2);
            Vector2 p15_2_ = fun.Polar(p15_1_, fha_, thl * 2);
            Line line1_ = new Line(p14_1_, p14_2_);
            Arc arc1_ = fun.DrawArc5(p12_, line1_, p14_);
            Arc arc2_ = fun.DrawArc4(p10_, arc1_.Radius, p8_, 0);
            Arc arc3_ = fun.DrawArc4(p4_, arc2_.Radius, p13_, 0);
            Arc arc4_ = fun.DrawArc4(p15_, arc1_.Radius, p16_, 0);
            var polyline1_ = Pus.AddPointsToLwPolyLine(p5_, p6_, p3_, p1_, p2_, p4_, p8_, p7_);
            Vector2 p17_0_ = fun.Polar(p10_, pi / 2 + pi / 4, thl * 2);
            Vector2 p17_ = fun.Inters1(p10_, p17_0_, arc1_, 0);
            Vector2 p18_0_ = fun.Polar(p17_, fun.CalAngle(p17, p10) - pi / 2, thl * 2);
            Vector2 p18_ = fun.Inters1(p17_, p18_0_, arc2_, 1);
            Vector2 p19_0_ = fun.Polar(p16_, 165 * pi / 180, thl * 2);
            Vector2 p19_ = fun.Inters1(p16_, p19_0_, arc3_, 1);
            Vector2 p20_0_ = fun.Polar(p19_, fun.CalAngle(p19_, p16_) - pi / 2, thl * 2);
            Vector2 p20_ = fun.Inters1(p19_, p20_0_, arc4_, 0);
            Vector2 p21_1_ = fun.Polar(p12_, pi, thl / 4.0 * 2);
            Vector2 p21_2_ = fun.Polar(p12_1_, pi / -2, thl * 2);
            Vector2 p21_ = fun.Inters1(p21_1_, p21_2_, arc1_, 1);
            Vector2 p21_3_ = fun.Polar(p0_, pi / 2, td / 2.0 * 2);
            Vector2 p21_4_ = fun.Polar(p21_3_, 0, thl * 2);
            Line line5_ = new Line(p21_3_, p21_4_);
            Arc arc5_ = fun.DrawArc5(p21_, line5_, p3_);
            Vector2 p22_ = fun.Polar(p3_, fun.CalAngle(p3_, p6_), fun.CalDistance(p3_, p6_) / 2.0);
            Vector2 p23_0_ = fun.Polar(p22_, fun.CalAngle(p3_, p21_) + 1 * pi / 180, oal * 2);
            Vector2 p23_ = fun.Inters1(p23_0_, p22_, arc1_, 0);
            Arc arc6_ = fun.DrawArc4(p23_, arc5_.Radius, p22_, 0);
            Vector2 p24_0_ = fun.Polar(p6_, fun.CalAngle(p5_, p6_), thl * 2);
            Vector2 p25_0_ = fun.Polar(p3_, fun.CalAngle(p1_, p3_), thl * 2);
            var polyline2_ = Pus.AddPointsToLwPolyLine(p18_, p17_, p10_, p16_, p19_, p17_, p19_, p20_);
            var a2c_ = Pus.ToV2(arc2_.Center);//arc2的圆心
            var a3c_ = Pus.ToV2(arc3_.Center);//arc3的圆心
            var z1_ = fun.CalAngle(a2c_, p18_) - fun.CalAngle(a2c_, p10_);//一个齿的向量            
            double xl1_ = fun.CalAngle(a2c_, p8_) - fun.CalAngle(a2c_, p10_);//arc2的向量
            double zc1_ = (arc2_.Radius * 2) * pi;//arc2的满园时的周长
            double zc1_1_ = (xl1_ / (2 * pi)) * zc1_;//arc2弧线的周长
            double zc1_2_ = (z1_ / (2 * pi)) * zc1_;
            int cs1_ = (int)(zc1_1_ / zc1_2_);//arc2弧线上有多少个齿
            double i_ = 0;
            Vector2 c1_ = p18_;
            Vector2 c2_ = p20_;
            Vector2 c4_;
            do
            {
                Vector2 c3_ = fun.PointRotate(a2c_, p17_, 2 * pi - z1_ * i_);
                c4_ = fun.PointRotate(a2c_, p18_, 2 * pi - z1_ * i_);
                Vector2 c5_ = fun.PointRotate(a3c_, p19_, 2 * pi + z1_ * i_);
                Vector2 c6_ = fun.PointRotate(a3c_, p20_, 2 * pi + z1_ * i_);
                var polyline3_ = Pus.AddPointsToLwPolyLine(c4_, c3_, c1_, c2_, c5_, c3_, c5_, c6_);
                if (i_ < cs1_)
                {
                    polyline3_ = Pus.AddPointsToLwPolyLine(c4_, c3_, c1_, c2_, c5_, c3_, c5_, c6_);
                   // fun.PolyFill(dxf, polyline3_, 0.5, contour);
                    if (i_ == cs1_ - 1)
                    {
                        polyline3_ = Pus.AddPointsToLwPolyLine(c4_, c6_, p4_, p8_, c4_);
                     //   fun.PolyFill(dxf, polyline3_, 0.5, contour);
                    }
                }
                i_++;
                c1_ = c4_;
                c2_ = c6_;
            } while (i_ < cs1_);
            var a5c_ = Pus.ToV2(arc5_.Center);
            var a6c_ = Pus.ToV2(arc6_.Center);
            var a5x_ = fun.CalAngle(a5c_, p3_) - fun.CalAngle(a5c_, p21_);//arc5的向量
            var a5zh_ = arc5_.Radius * 2 * pi;
            var a5d_ = a5x_ / (pi * 2) * a5zh_;//arc5弧线周长
            Vector2 c4_0_ = fun.Polar(c4_, pi / 2, thl * 2);
            Vector2 p24_ = fun.Inters(c4_, c4_0_, p6_, p24_0_);
            Vector2 p25_ = fun.Inters(c4_, c4_0_, p3_, p25_0_);
            Vector2 p26_0_ = fun.Polar(p25_, pi / -4, thl * 2);
            Vector2 p26_ = fun.Inters1(p25_, p26_0_, arc6_, 0);
            Vector2 p27_0_ = fun.Polar(p26_, pi / 4, thl * 2);
            Vector2 p27_ = fun.Inters1(p26_, p27_0_, arc5_, 1);
            Vector2 p28_ = fun.Polar(p26_, pi / -2, fun.CalDistance(p25_, p24_));
            Vector2 p29_ = fun.Polar(p27_, pi / -2, fun.CalDistance(p25_, p24_));
            var z2_ = fun.CalAngle(a5c_, p25_) - fun.CalAngle(a5c_, p27_);//一个齿的向量
            var z2d_ = z2_ / (2 * pi) * a5zh_;//齿2在arc5中的周长
            int cs2_ = (int)(a5d_ / z2d_);
            double n_ = 0;
            double m_ = fun.CalDistance(p25_, p24_);
            Vector2 d1_ = p25_;
            Vector2 d4_ = p24_;
            for (; n_ < cs2; n_++)
            {
                Vector2 d2_ = fun.PointRotate(a5c_, p26_, z2_ * n_);
                Vector2 d3_ = fun.PointRotate(a5c_, p27_, z2_ * n_);
                Vector2 d6_ = fun.Polar(d3_, pi / -2, m_);
                if (m_ > 1)
                {
                    d4_ = fun.Polar(d1_, pi / -2, m_);
                    Vector2 d5_ = fun.Polar(d2_, pi / -2, m_);
                    d6_ = fun.Polar(d3_, pi / -2, m_);
                    var polyline5_ = Pus.AddPointsToLwPolyLine(d1_, d2_, d3_, d6_, d5_, d2_, d5_, d4_);
                   // fun.PolyFill(dxf, polyline5_, 0.5, contour);
                }
                else
                {
                    if (n_ == cs2_ - 1)
                    {
                        Vector2 di_0_ = fun.Polar(d1_, pi / -4, thl * 2);
                        Vector2 di_ = fun.Inters1(d1_, di_0_, arc1_, 0);
                        Line lineq1_ = new Line(d1_, di_);
                      //  fun.drawBline(dxf, lineq1_, 0.5, contour);
                    }
                    else
                    {
                        m_ = 0;
                        d4_ = fun.Polar(d1_, pi / -2, m_);
                        Vector2 d5_ = fun.Polar(d2_, pi / -2, m_);
                        d6_ = fun.Polar(d3_, pi / -2, m_);
                        var polyline5_ = Pus.AddPointsToLwPolyLine(d1_, d2_, d3_, d6_, d5_, d2_, d5_, d4_);
                      //  fun.PolyFill(dxf, polyline5_, 0.5, contour);
                    }
                }
                d1_ = d3_;
                d4_ = d6_;
                m_ -= 0.5 * 2 / scale;
            }
            Vector2 p30_ = fun.Polar(p11_, pi / 2, fun.CalDistance(p3_, p6_) * (3 / 2.0) * 2);
            Vector2 p31_1_ = fun.Polar(fun.Polar(p15_, pi / -2, td / 2.0), 0, (p11_.X - p15_.X) * (3 / 22.0) * 2);
            Vector2 p31_2_ = new Vector2(p31_1_.X, p31_1_.Y + thl);
            Vector2 p31_ = fun.Inters1(p31_1_, p31_2_, arc4_, 0);
            Vector2 p11_1_ = fun.Polar(p0_, pi / -2, td / 2.0 * 2);
            Vector2 p11_2_ = fun.Polar(p11_1_, 0, thl * 2);
            Line line6_ = new Line(p11_1_, p11_2_);
            Arc arc7_ = fun.DrawArc5(p31_, line6_, p11_);
            Arc arc8_ = fun.DrawArc4(p31, arc7_.Radius, p30, 0);
            Vector2 a7c_ = Pus.ToV2(arc7_.Center);
            Vector2 p32_ = fun.Polar(p11_, fun.CalAngle(a7c_, p11_), fun.CalDistance(p25_, p26_));
            Vector2 p33_ = fun.Polar(p31_, fun.CalAngle(a7c_, p31_), fun.CalDistance(p25_, p26_));
            Arc arc9_ = fun.DrawArc4(p33_, arc7_.Radius + fun.CalDistance(p25_, p26_), p32_, 0);
            Vector2 p34_0_ = fun.Polar(p11_, -126 * pi / 180, thl * 2);
            Vector2 p34_ = fun.Inters1(p34_0_, p11_, arc9_, 0);
            Vector2 p35_0_ = fun.Polar(p34_, fun.CalAngle(p34_, p11_) + pi / 2, thl * 2);
            Vector2 p35_ = fun.Inters1(p34_, p35_0_, arc7_, 1);
            Vector2 p36_ = fun.Polar(p34_, pi / 2, fun.CalDistance(p30_, p11_));
            Vector2 p37_ = fun.Polar(p35_, pi / 2, fun.CalDistance(p30_, p11_));
            double z3_ = fun.CalAngle(a7c_, p35_) - fun.CalAngle(a7c_, p11_);//一个齿的向量
            var a7x_ = fun.CalAngle(a7c_, p31_) - fun.CalAngle(a7c_, p11_);//arc7的向量
            var a7zh_ = arc7_.Radius * 2 * pi;
            var a7d_ = a7x_ / (pi * 2) * a7zh_;//arc7弧线周长
            var z3d_ = z3_ / (2 * pi) * a7zh_;//齿2在arc7中的周长
            int cs3_ = (int)(a7d_ / z3d_);//齿2在arc7的数量
            i_ = 0;
            n_ = fun.CalDistance(p30_, p11_);
            c1_ = p11_;
            c4_ = p30_;
            for (; i_ < cs3_ + 1; i_++)
            {
                if (n_ > 1)
                {
                    n_ = n_;
                }
                else
                {
                    n_ = 0;
                }
                c2_ = fun.PointRotate(a7c_, p34_, -z3_ * i_);
                var c3_ = fun.PointRotate(a7c_, p35_, -z3_ * i_);
                var c5_ = fun.Polar(c2_, pi / 2, n_);
                var c6_ = fun.Polar(c3_, pi / 2, n_);
                var polyline6_ = Pus.AddPointsToLwPolyLine(c6_, c5_, c4_, c1_, c2_, c5_, c2_, c3_);
                if (i_ == cs3_)
                {
                    var c3_0_ = fun.Polar(c3_, fun.CalAngle(c2_, c3_), thl * 2);
                    var c3_1_ = fun.Inters1(c3_, c3_0_, arc3_, 1);
                    polyline6_ = Pus.AddPointsToLwPolyLine(c6_, c5_, c4_, c1_, c2_, c5_, c2_, c3_1_);
                }
                else
                {
                    polyline6_ = Pus.AddPointsToLwPolyLine(c6_, c5_, c4_, c1_, c2_, c5_, c2_, c3_);
                }
              //  fun.PolyFill(dxf, polyline6_, 0.5, contour);
                c4_ = c6_;
                c1_ = c3_;
                n_ -= 1.5 * 2 / scale;
            }
            Vector2 p38_0_ = fun.Polar(p11_, pi / 4 + 0.1 * pi / 180, thl * 2);
            Vector2 p38_1_ = fun.Polar(p0_, pi / -2 - 0.1 * pi / 180, dn / 2.0 * 2);
            Vector2 p38_2_ = fun.Polar(p38_1_, 0, thl * 2);
            Vector2 p38_3_ = fun.Polar(p10_, pi / -4, thl * 2);
            Vector2 p38_4_ = fun.Polar(p0_, pi / 2, dn / 2.0 * 2);
            Vector2 p38_5_ = fun.Polar(p38_4_, 0, thl * 2);
            Vector2 p38_ = fun.Inters(p11_, p38_0_, p38_1_, p38_2_);
            Vector2 p39_ = fun.Inters(p10_, p38_3_, p38_4_, p38_5_);
            Vector2 p40_ = fun.Polar(p0_, 0, oal * 2);
            Vector2 p41_ = fun.Polar(p40_, pi / 2, dconms / 2.0 * 2);
            Vector2 p42_ = fun.Polar(p41_, pi, ls * 2);
            Vector2 p43_0_ = fun.Polar(p42_, pi + pi / 4, thl * 2);
            Vector2 p43_ = fun.Inters(p42_, p43_0_, p38_4_, p38_5_);
            Vector2 p46_ = fun.mirrorpoint(p43_, p0_1_, p0_2_);
            Arc arc10_ = fun.DrawArc5(p30_, new Line(p39_, p38_), p16_);
            Vector2 p55 = fun.Polar(p0, pi, td * 3.5);
            Vector2 p56 = fun.Polar(p55, pi / 2, td);
            Vector2 p57 = fun.Polar(p55, pi / -2, td * 1.2);
            Vector2 p58 = fun.Polar(p56, -10 * pi / 180, td / 9.0);
            Vector2 p71 = fun.Polar(p58, -23 * pi / 180, td * (1.5 / 18.0));
            Vector2 p59 = fun.Polar(p58, -59 * pi / 180, td * (5.77 / 18.0));
            Vector2 p60 = fun.Polar(p59, -28 * pi / 180, td * (17 / 45.0));
            Vector2 p61 = fun.Polar(p60, -25 * pi / 180, td * (5.5 / 18.0));
            Vector2 p62 = fun.Polar(p61, pi / -4, td * (4.8 / 18.0));
            Vector2 p63 = fun.Polar(p62, -74 * pi / 180, td * (7.5 / 18.0));
            Vector2 p64 = fun.Polar(p63, -69 * pi / 180, td * (7 / 18.0));
            Vector2 p65 = fun.Polar(p64, -108 * pi / 180, td * (3.8 / 18.0));
            Vector2 p66 = fun.Polar(p65, -119 * pi / 180, td * (7.63 / 18.0));
            Vector2 p67 = fun.Polar(p66, -142 * pi / 180, td * (3.19 / 18.0));
            Vector2 p68 = fun.Polar(p67, -176 * pi / 180, td * (7.238 / 18.0));
            Vector2 p69 = fun.Polar(p57, pi / 2, -(p57.Y - p65.Y) + ((p57.Y - p65.Y) / 10.0));
            Vector2 p70 = fun.Polar(p55, pi / -2, td * (5 / 18.0));
            Vector2 p72 = fun.Polar(p55, pi / 2, td * (5 / 18.0));
            Vector2 p73 = fun.Polar(p55, pi, td * (3 / 18.0));
            Vector2 p74 = fun.Polar(p56, pi / -2, td * (0.84 / 18.0));
            var polyline4_ = Pus.AddPointsToLwPolyLine(p3_, p6_, p24_, p25_, p3_);
            var polyline7_ = Pus.AddPointsToLwPolyLine(p13_, p10_, p39_, p38_, p39_, p43_, p46_, p38_, p11_, p30_, p11_, p38_);
            var polyline8_ = Pus.AddPointsToLwPolyLine(p55, p56, p71, p59, p61, p62, p63, p64, p66, p67, p68, p57, p69, p65, p69, p70, p73, p72, p70, p74, p58);
            var polyline9_ = Pus.AddPointsToLwPolyLine(p57, p70, p73, p72, p70, p56);
            polyline8_.Vertexes[1].Bulge = -Math.Tan((66 * pi / 180) / 4);
            polyline8_.Vertexes[2].Bulge = -Math.Tan((16 * pi / 180) / 4);
            polyline8_.Vertexes[3].Bulge = Math.Tan((34 * pi / 180) / 4);
            polyline8_.Vertexes[4].Bulge = -Math.Tan((57 * pi / 180) / 4);
            polyline8_.Vertexes[5].Bulge = Math.Tan((28 * pi / 180) / 4);
            polyline8_.Vertexes[6].Bulge = -Math.Tan((7 * pi / 180) / 4);
            polyline8_.Vertexes[7].Bulge = -Math.Tan((22 * pi / 180) / 4);
            polyline8_.Vertexes[8].Bulge = -Math.Tan((26 * pi / 180) / 4);
            polyline8_.Vertexes[9].Bulge = -Math.Tan((52 * pi / 180) / 4);
            polyline8_.Vertexes[10].Bulge = Math.Tan((49 * pi / 180) / 4);
            polyline8_.Vertexes[12].Bulge = Math.Tan((22 * pi / 180) / 4);
            polyline8_.Vertexes[13].Bulge = -Math.Tan((22 * pi / 180) / 4);
            polyline8_.Vertexes[19].Bulge = -Math.Tan((10 * pi / 180) / 4);
            polyline8_.Lineweight = Lineweight.W35;//Lineweight指线宽   
            polyline8_.Layer = additionalline;//Layer指图层
            /* dxf.AddEntity(new EntityObject[] { polyline1_,polyline2_,polyline4_,polyline7_,polyline8_ ,polyline9_ 
             ,arc1_,arc2_,arc3_,arc4_,arc5_ ,arc6_ ,arc7_,arc8_ ,arc9_
              ,arc10_
             });*/
           /* fun.PolyFill(dxf, polyline1_, 0.5, contour);
            fun.PolyFill(dxf, polyline2_, 0.5, contour);
            fun.PolyFill(dxf, polyline4_, 0.5, contour);
            fun.PolyFill(dxf, polyline7_, 0.5, contour);
            fun.PolyFill(dxf, polyline8_, 0.5, contour);
            fun.PolyFill(dxf, polyline9_, 0.35, contour);
            fun.drawBArc(dxf, arc10_, 0.5, contour);*/
            Vector2 v1 = fun.Polar(p1, 0, lu);
            Vector2 v2 = fun.Polar(p0, 0, lpr);
            Vector2 v3 = fun.Polar(p3, pi / 2, 0.1);
            Vector2 v4 = fun.Polar(p11, pi, -z3d * 5);
            Vector2 v5 = fun.Polar(v4, pi, -z3d);
            Vector2 v6 = fun.Polar(p15_, 0, tcl);
            Vector2 v7 = fun.Inters1(p0_1, p0_2, arc1, 0);
            Vector2 v7_1 = fun.Polar(v7, fha_, 0.1);
            Vector2 v7_2 = fun.Polar(v7, 0, 0.1);
            Vector2 v8 = fun.Polar(p42, 0, fun.CalDistance(p42, p41) / 2.5);
            Vector2 v9 = fun.Polar(p11, pi, fun.CalDistance(p4, p11) / 20.0);
            Vector2 v10 = fun.Polar(p0, pi + pi / 4, td * 2);
            Vector2 v11 = fun.Polar(p55, pi / -2, td * 1.5);
            Vector2 v12 = fun.Polar(v11, pi / 2, td / 10.0);
            Vector2 v13 = fun.Polar(p73, pi / -2, td * 2);
            Vector2 v14 = fun.Polar(v13, pi / 2, td / 10.0);
            Vector2 v15 = fun.Polar(v6, pi / -2, td * 2);
            Vector2 v16 = fun.Polar(v6, pi / -2, td * 1.5);
            Vector2 v17 = fun.Polar(p40, pi / 3, 2 * 1.7 * scale);
            Vector2 v18 = fun.Polar(v17, pi / 3, dconms);
            Vector2 v19 = fun.Polar(v2, pi / 3, 2 * scale * 1.7);
            Vector2 v20 = fun.Polar(v19, pi / 3, dconms / 1.5);
            Vector2 v21 = fun.Polar(p0, 75 * pi / 180, 2 * 1.7 * scale);
            Vector2 v22 = fun.Polar(v21, 75 * pi / 180, dconms);
            Vector2 v23 = fun.Polar(p4, pi / -6, 2 * 1.7 * scale);
            Vector2 v24 = fun.Polar(v23, pi / -6, dconms / 4.0);
            Vector2 v25 = fun.Polar(p0_, pi / 2 + pi / 6, 2 * 1.7 * scale);
            Vector2 v26 = fun.Polar(v25, pi / 2 + pi / 6, dconms);
            Vector2 v27 = fun.Polar(v6, pi / -4, 1.7 * 2 * scale);
            Vector2 v28 = fun.Polar(v27, pi / -4, dconms / 4.0);
            Vector2 v29 = fun.Polar(p55, pi + pi / 4, 2 * 1.7 * scale);
            Vector2 v30 = fun.Polar(v29, pi + pi / 4, dconms / 2.0);
            fun.dimrot1(dxf, p1, p12, 0, td - ((p12.Y - p1.Y) / 2.0 + p1.Y), 2, 2.2 * scale, 2.6 * scale, 0.9, "THL", "", "");
            fun.dimrot1(dxf, p1, v1, 0, td * 1.3 - ((p1.Y - v1.Y) / 2.0 + v1.Y), 2, 2.2 * scale, 2.6 * scale, 0.9, "LU", "", "");
           //fun.dimrot1(dxf, p0, v2, 0, td * 1.6, 2, 2.2 * scale, 2.6 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p0, p40, 0, td * 1.9, 2, 2.2 * scale, 2.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p42, p41, 0, td * 1.3 - p41.Y, 2, 2.2 * scale, 2.6 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p2, p1, 90, td, 2, 2.2 * scale, 2.6 * scale, 0.9, "TCPD", "", "");
            fun.dimrot1(dxf, v3, p15, 90, td * 1.3 + p3.X, 2, 2.2 * scale, 2.6 * scale, 0.9, "TD", "", "");
            fun.dimrot1(dxf, p2, p4, 180, td - (p4.Y - p2.Y) / 2.0 + p2.Y, 2, 2.2 * scale, 2.6 * scale, 0.9, "TCPL", "", "");
          /*  fun.dimrot1(dxf, p4, v2, 180, td * 1.3 - (p4.Y - p0.Y) / 2.0, 2, 2.2 * scale, 2.6 * scale, 0.9, "LTA", "", "");
            fun.dimrot1(dxf, p4, p40, 180, td * 1.6 - (p4.Y - p40.Y) / 2.0, 2, 2.2 * scale, 2.6 * scale, 0.9, "LF", "", "");
            fun.dimrot1(dxf, v4, v5, 180, td + p4.Y, 2, 2.2 * scale, 2.6 * scale, 0.9, "TP", "", "");
            fun.dimrot1(dxf, p52, p51, 180, td + p52.Y, 2, 2.2 * scale, 2.6 * scale, 0.9, "DRVL", "", "");*/
            fun.dimrot1(dxf, p41, p44, -90, td, 2, 2.2 * scale, 2.6 * scale, 0.9, "DCONMS", "", "");
           /* fun.dimrot1(dxf, p1_, p2_, 90, td, 2, 2.2 * scale, 2.6 * scale, 0.9, "TCPD", "", "");
            fun.dimrot1(dxf, p15_, fun.Polar(p3_, pi / 2, 0.1), 90, td * 2.5, 2, 2.2 * scale, 2.6 * scale, 0.9, "TD", "", "");
            fun.dimrot1(dxf, p2_, v6, 180, td, 2, 2.2 * scale, 2.6 * scale, 0.9, "TCL", "", "");*/
            fun.jdbz2(dxf, new Line(v7, v7_2), new Line(v7, v7_1), thl, 2.2 * scale, 2.6 * scale, 0.9, "FHA", "", "");
            //fun.jdbz2(dxf, new Line(p4_, fun.Polar(p4_, tg_/-2, 10)), new Line(p3_, fun .Polar (p3_,tg_/2,10) ),thl*1.5, 2.2 * scale, 2.6 * scale, 0.9, "TG", "", "");
           /* fun.Axis(dxf, fun.Polar(p40, pi / -3, td * 2), 0, -90, "Z", "X", "Y", 2.2 * scale, 2.6 * scale, 0);
            fun.Axis(dxf, p0, 0, -90, "", "", "", 2 * scale, 2.2 * scale, 0);
            fun.Axis(dxf, p40, 0, -90, "", "", "", 2 * scale, 2.2 * scale, 0);
            fun.Axis(dxf, v2, 0, -90, "", "", "", 2 * scale, 2.2 * scale, 0);
            fun.Axis(dxf, p0_, 0, -90, "", "", "", 2 * scale, 2.2 * scale, 0);
            fun.Axis(dxf, p55, 0, -90, "", "", "", 2 * scale, 2.2 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v8, 70, fun.Polar(v8, 70 * pi / 180, dconms / 3), fun.Polar(v8, 70 * pi / 180, dconms / 1.5), 2.2 * scale, 2.6 * scale);
            fun.Singlelinearrow(dxf, "TDZ", v9, -45, fun.Polar(v9, -pi / 4, dconms / 2.0), fun.Polar(v9, -pi / 4, dconms), 2.2 * scale, 2.6 * scale);
            fun.Singlelinearrow(dxf, "FDP", v10, 180, fun.Polar(v10, 0, dconms / 2.0), fun.Polar(v10, 0, dconms), 2.2 * scale, 2.6 * scale);
            fun.Singlelinearrow(dxf, "THL", v12, 180, fun.Polar(v12, 0, dconms / 2.0), fun.Polar(v12, 0, dconms), 2.2 * scale, 2.6 * scale);
            fun.Singlelinearrow(dxf, "OAL,LPR", v14, 180, fun.Polar(v14, 0, dconms / 2.0), fun.Polar(v14, 0, dconms), 2.2 * scale, 2.6 * scale);
            fun.Singlelinearrow(dxf, "LF", v16, 180, fun.Polar(v16, 0, dconms / 2.0), fun.Polar(v16, 0, dconms), 2.2 * scale, 2.6 * scale);
            fun.Singlelinearrow(dxf, "LTA", v15, 180, fun.Polar(v15, 0, dconms / 2.0), fun.Polar(v15, 0, dconms), 2.2 * scale, 2.6 * scale);
           */Line linev1 = new Line(p55, v11);
            Line linev2 = new Line(p73, v13);
            Line linev3 = new Line(v6, v15);
            Line linev4 = new Line(v18, v17);
            Line linev5 = new Line(v19, v20);
            Line linev6 = new Line(v21, v22);
            Line linev7 = new Line(v23, v24);
            Line linev8 = new Line(v25, v26);
            Line linev9 = new Line(v27, v28);
            Line linev10 = new Line(v29, v30);
            Text txt1 = new Text("PCS", v18, 2.2 * scale, 0);
            Text txt2 = new Text("MCS", v20, 2.2 * scale, 0);
            Text txt3 = new Text("CIP", v22, 2.2 * scale, 0);
            Text txt4 = new Text("CRP", fun.Polar(v24, pi / -2, 2.2 * scale), 2.2 * scale, 0);
            Text txt5 = new Text("CIP", v26, 2.2 * scale, 0);
            Text txt6 = new Text("CRP", fun.Polar(v28, pi / -2, 2.2 * scale), 2.2 * scale, 0);
            Text txt7 = new Text("CIP", v30, 2.2 * scale, 0);
            Circle circle1 = new Circle(p0, 1.7 * 2 * scale);
            Circle circle2 = new Circle(p4, 1.7 * 2 * scale);
            Circle circle3 = new Circle(v6, 1.7 * 2 * scale);
            Circle circle4 = new Circle(p0_, 1.7 * 2 * scale);
            Line linev11 = new Line(p0_1, p0_2);
            linev11.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev11.Layer = additionalline;//Layer指图层
            linev11.LinetypeScale = 5 * scale;//指线性比例
            linev11.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的

            /*dxf.AddEntity(new EntityObject[] { linev1, linev2 ,linev3,linev4,linev5 ,linev6,linev7,linev8 ,linev9,linev10 ,linev11
            ,txt1 ,txt2 ,txt3,txt4 ,txt5 ,txt6 ,txt7
            ,circle1 ,circle2 ,circle3,circle4
            });*/


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}


